Skip to content

Conversation

A4-Tacks
Copy link
Contributor

Add support for else-block of never-type for convert_to_guarded_return

Example

fn main() {
    if$0 let Ok(x) = Err(92) {
        foo(x);
    } else {
        return
    }
}

Before this PR:

Assist not applicable

After this PR:

fn main() {
    let Ok(x) = Err(92) else {
        return
    };
    foo(x);
}

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 27, 2025
// if !cond {
// return;
// }
// if !cond { return }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall but I think we'd prefer the former return; stmt over { return } as rustfmt does so

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will make it more compact in let-chain

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay

Add support for else-block of never-type for `convert_to_guarded_return`

Example
---
```rust
fn main() {
    if$0 let Ok(x) = Err(92) {
        foo(x);
    } else {
        return
    }
}
```

**Before this PR**:

Assist not applicable

**After this PR**:

```rust
fn main() {
    let Ok(x) = Err(92) else {
        return
    };
    foo(x);
}
```
@A4-Tacks
Copy link
Contributor Author

@ShoyuVanilla Do you have time to review this PR and some older PRs?

@ShoyuVanilla
Copy link
Member

Yes, but one or two days later. I have to fix some cargo related issues as they worsen developer experiences for some people by a lot 😅

@ShoyuVanilla
Copy link
Member

But I'll review some relatively simple PRs before then

@ShoyuVanilla ShoyuVanilla added this pull request to the merge queue Oct 14, 2025
Merged via the queue into rust-lang:master with commit 4229c91 Oct 14, 2025
15 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 14, 2025
@lnicola lnicola changed the title Add else-block support for convert_to_guarded_return fix: support else blocks with ! return type in convert_to_guarded_return Oct 14, 2025
@A4-Tacks A4-Tacks deleted the guarded-if-let-else branch October 14, 2025 09:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants